// 把api引入
import * as api from '../services/example'

export default {
  namespace: 'product',
  state: {
    productList:[
       {
         name:'豆子'
       },
       {
         name:'玉米'
       }
    ]
  },
  reducers: {
    updateList(state,action) {
      const productList = state.productList.concat(action.payload)
      return { ...state, productList };
    },
  },
  // 异步操作
  effects:{
    *updateListAsync({payload},{call,put}){
      yield put({
        type:'updateList',
        payload            //传的参数
      })
    },

    *updateListHttp({payload},{call,put}){
      // 网络请求
      const result = yield call(api.getProduct,payload)
      const data = result.data;
      if(data){
        yield put({
          type:'updateList',
          payload:data            //传的参数
        })
      }
      
    }
  }
};


